package com.sc.nft.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.UserCityServerCentre;
import com.sc.nft.entity.dto.GetUserCityServerCentreListDTO;
import com.sc.nft.entity.dto.GetUserCityServerCentrePageDTO;
import com.sc.nft.entity.vo.CityServerCentreExportVO;
import com.sc.nft.entity.vo.GetUserCityServerCentreListVO;
import com.sc.nft.entity.vo.GetUserCityServerCentrePageVO;
import com.sc.nft.entity.vo.UserWorkRoomExcludeWhiteListRankVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface UserCityServerCentreMapper extends BaseMapper<UserCityServerCentre> {

    /**
     * 根据userId修改用户省市区
     *
     * @param userCityServerCentre
     * @return
     */
    Boolean byUserIdSaveModel(@Param("userCityServerCentre") UserCityServerCentre userCityServerCentre);


    List<GetUserCityServerCentreListVO> getUserCityServerCentreList(@Param("getUserCityServerCentreListDTO") GetUserCityServerCentreListDTO getUserCityServerCentreListDTO);

    /**
     * 根据当前城市服务中心的用户id查找他上级是否有城市服务中心,且只返回一个,返回的是用户id
     *
     * @param userId
     * @return
     */
    Long accessTheNearestCityServiceCenter(@Param("userId") Long userId);

    /**
     * 获取用户所在的所有城市服务中心 DaoId
     *
     * @param userId
     * @return
     */
    List<Long> getServiceCenterUserIdListByUserId(@Param("userId") Long userId);


    /**
     * 获取用户所在的所有品牌Dao DaoId
     *
     * @param userId
     * @return
     */
    List<Long> getDaoUserIdListByUserId(@Param("userId") Long userId);

    /**
     * 分页查询
     *
     * @param page
     * @param getUserCityServerCentrePageDTO
     * @return
     */
    Page<GetUserCityServerCentrePageVO> selectPage(Page page, @Param("getUserCityServerCentrePageDTO") GetUserCityServerCentrePageDTO getUserCityServerCentrePageDTO);

    /**
     * 获取团队的城市服务中心数量
     *
     * @param userId
     * @return
     */
    Integer teamCityServiceCenter(@Param("userId") Long userId);

    List<Long> getJuniorUserIds(@Param("participationSmeltUserId") Long participationSmeltUserId, @Param("participationSmeltUserIds") List<Long> participationSmeltUserIds);


    /**
     * 获取最近的服务中心
     *
     * @param userId
     * @return
     */
    @Select("select user_id  from sc_user_relevance where relevance_id=#{userId} and user_id in (select user_id from sc_user_city_server_centre where is_delete=0) order by lv asc limit 1")
    Long getNearServiceCity(@Param("userId") Long userId);

    @Select("select user_id from sc_user_city_server_centre where is_delete=0 and user_id in (select relevance_id from sc_user_relevance where user_id=#{userId})")
    List<Long> getNextServiceCity(@Param("userId") Long userId);

    /**
     * 导出城市服务中心
     *
     * @return
     */
    List<CityServerCentreExportVO> centerServerExport();

    /**
     * 获取城市服务中心排除白名单的用户
     *
     * @return
     */
    List<UserWorkRoomExcludeWhiteListRankVO> getUserCityServerCentreExcludeWhiteListRank();

    Integer getUserCityServerExcludeExchequerList(@Param("userId") Long userId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
}
